const Mock = require('mockjs');
import {
    parseUrl,
    Reponse
} from '@/common/utils'


let user_list = {
    admin: 'admin',
    18646726608: '2512',
};

// 登录
Mock.mock('/api/login', 'post', (request) => {
    const req = JSON.parse(request.body);
    // tslint:disable-next-line:variable-name

    let successLoginMsg = {
        "code": 0,
        "msg": "登陆成功",
        "user": {
            "userId": "abcdefg",
            "mobile": "13333333333",
            "roleId": "0",
            "username": "liujialong",
            "jobSeeker": {
                "name": "Serati",
                "age": "18",
                "gender": "男",
                "avatar": "https://gw.alipayobjects.com/zos/rmsportal/BiazfanxmamNRoxxVxka.png",
                "email": "abc@abc.com"
            },
            "company": {
                "comId": "",
                "comRole": "",
                "name": "",
                "introduce": "",
                "address": "",
                "linkman": "",
                "logo": "",
                "corporation": "",
                "licence": "",
                "createTime": "",
                "level": "",
                "authStatus": ""
            }
        },
        "token": "aaa.bbb.ddd"
    }

    if (user_list[req.username] === undefined) {
        return {
            code: 1,
            msg: '用户名不存在',
            data: null
        };
    } else if (user_list[req.username] !== req.password && req.type == 0) {
        return {
            code: 1,
            msg: '密码不正确',
            data: null
        };
    } else if (user_list[req.username] !== req.password && req.type == 1) {
        return {
            code: 1,
            msg: '验证码不正确',
            data: null
        };
    }
    return successLoginMsg;
});

// 注册
Mock.mock('/api/register', 'post', (request) => {
    const req = JSON.parse(request.body);
    // tslint:disable-next-line:variable-name

    if (user_list[req.username] !== undefined) {
        return {
            code: 1,
            msg: '用户名已被注册',
            data: null
        };
    } else if (user_list[req.mobile] !== undefined) {
        return {
            code: 1,
            msg: '该手机号已注册',
            data: null
        };
    } else if (user_list[req.username] === undefined && user_list[req.mobile] === undefined) {
        user_list[req.username] = req.password;
        return {
            code: 0,
            msg: '注册成功',
            data: null
        };
    }

});

// 职位列表
let positionList = {
    "pageNumber": 1,
    "pageSize": 10,
    "total": 20,
    "totalPages": 2,
    "rows": [{
            "id": '1',
            "jobId": "aaaaaa",
            "jobFairId": "bbbbbb",
            "comId": "cccccc",
            "comName": "长春今非昔比",
            "posName": "web前端开发工程师",
            "posNature": "有限公司",
            "posArea": "长春",
            "salary": "3000-5000",
            "partment": "技术部",
            "education": "4",
            "experience": 4,
            "gender": "不限",
            "age": "18-28",
            "wantedNum": "5",
            "jobDescrib": "java开发",
            "linkman": "hr",
            "mobile": "13333333333",
            "email": "abc@abc.com",
            "address": "长春",
            "jobFairName": "长春招聘会",
            "level": "50-100"
        }, {
            "id": '2',
            "jobId": "aaaaaa",
            "jobFairId": "bbbbbb",
            "comId": "cccccc",
            "comName": "长春今非昔比",
            "posName": "java开发工程师",
            "posNature": "有限公司",
            "posArea": "长春",
            "salary": "3000-5000",
            "partment": "技术部",
            "education": "4",
            "experience": 1,
            "gender": "不限",
            "age": "18-28",
            "wantedNum": "5",
            "jobDescrib": "java开发",
            "linkman": "hr",
            "mobile": "13333333333",
            "email": "abc@abc.com",
            "address": "长春",
            "jobFairName": "长春招聘会",
            "level": "50-100"
        }, {
            "id": '3',
            "jobId": "aaaaaa",
            "jobFairId": "bbbbbb",
            "comId": "cccccc",
            "comName": "长春今非昔比",
            "posName": "java开发工程师",
            "posNature": "有限公司",
            "posArea": "长春",
            "salary": "3000-5000",
            "partment": "技术部",
            "education": "4",
            "experience": 0,
            "gender": "不限",
            "age": "18-28",
            "wantedNum": "5",
            "jobDescrib": "java开发",
            "linkman": "hr",
            "mobile": "13333333333",
            "email": "abc@abc.com",
            "address": "长春",
            "jobFairName": "长春招聘会",
            "level": "50-100"
        }, {
            "id": '4',
            "jobId": "aaaaaa",
            "jobFairId": "bbbbbb",
            "comId": "cccccc",
            "comName": "长春今非昔比",
            "posName": "java开发工程师",
            "posNature": "有限公司",
            "posArea": "长春",
            "salary": "3000-5000",
            "partment": "技术部",
            "education": "4",
            "experience": 1,
            "gender": "不限",
            "age": "18-28",
            "wantedNum": "5",
            "jobDescrib": "java开发",
            "linkman": "hr",
            "mobile": "13333333333",
            "email": "abc@abc.com",
            "address": "长春",
            "jobFairName": "长春招聘会",
            "level": "50-100"
        }, {
            "id": '5',
            "jobId": "aaaaaa",
            "jobFairId": "bbbbbb",
            "comId": "cccccc",
            "comName": "长春今非昔比",
            "posName": "java开发工程师",
            "posNature": "有限公司",
            "posArea": "长春",
            "salary": "3000-5000",
            "partment": "技术部",
            "education": "4",
            "experience": 1,
            "gender": "不限",
            "age": "18-28",
            "wantedNum": "5",
            "jobDescrib": "java开发",
            "linkman": "hr",
            "mobile": "13333333333",
            "email": "abc@abc.com",
            "address": "长春",
            "jobFairName": "长春招聘会",
            "level": "50-100"
        }, {
            "id": '6',
            "jobId": "aaaaaa",
            "jobFairId": "bbbbbb",
            "comId": "cccccc",
            "comName": "长春今非昔比",
            "posName": "java开发工程师",
            "posNature": "有限公司",
            "posArea": "长春",
            "salary": "3000-5000",
            "partment": "技术部",
            "education": "4",
            "experience": 1,
            "gender": "不限",
            "age": "18-28",
            "wantedNum": "5",
            "jobDescrib": "java开发",
            "linkman": "hr",
            "mobile": "13333333333",
            "email": "abc@abc.com",
            "address": "长春",
            "jobFairName": "长春招聘会",
            "level": "50-100"
        },
        {
            "id": '7',
            "jobId": "aaaaaa",
            "jobFairId": "bbbbbb",
            "comId": "cccccc",
            "comName": "长春今非昔比",
            "posName": "java开发工程师",
            "posNature": "有限公司",
            "posArea": "长春",
            "salary": "3000-5000",
            "partment": "技术部",
            "education": "4",
            "experience": 1,
            "gender": "不限",
            "age": "18-28",
            "wantedNum": "5",
            "jobDescrib": "java开发",
            "linkman": "hr",
            "mobile": "13333333333",
            "email": "abc@abc.com",
            "address": "长春",
            "jobFairName": "长春招聘会",
            "level": "50-100"
        },
        {
            "id": '8',
            "jobId": "aaaaaa",
            "jobFairId": "bbbbbb",
            "comId": "cccccc",
            "comName": "长春今非昔比",
            "posName": "java开发工程师",
            "posNature": "有限公司",
            "posArea": "长春",
            "salary": "3000-5000",
            "partment": "技术部",
            "education": "4",
            "experience": 1,
            "gender": "不限",
            "age": "18-28",
            "wantedNum": "5",
            "jobDescrib": "java开发",
            "linkman": "hr",
            "mobile": "13333333333",
            "email": "abc@abc.com",
            "address": "长春",
            "jobFairName": "长春招聘会",
            "level": "50-100"
        },
        {
            "id": '9',
            "jobId": "aaaaaa",
            "jobFairId": "bbbbbb",
            "comId": "cccccc",
            "comName": "长春今非昔比",
            "posName": "java开发工程师",
            "posNature": "有限公司",
            "posArea": "长春",
            "salary": "3000-5000",
            "partment": "技术部",
            "education": "4",
            "experience": 1,
            "gender": "不限",
            "age": "18-28",
            "wantedNum": "5",
            "jobDescrib": "java开发",
            "linkman": "hr",
            "mobile": "13333333333",
            "email": "abc@abc.com",
            "address": "长春",
            "jobFairName": "长春招聘会",
            "level": "50-100"
        },
        {
            "id": '10',
            "jobId": "aaaaaa",
            "jobFairId": "bbbbbb",
            "comId": "cccccc",
            "comName": "长春今非昔比",
            "posName": "java开发工程师",
            "posNature": "有限公司",
            "posArea": "长春",
            "salary": "3000-5000",
            "partment": "技术部",
            "education": "4",
            "experience": 1,
            "gender": "不限",
            "age": "18-28",
            "wantedNum": "5",
            "jobDescrib": "java开发",
            "linkman": "hr",
            "mobile": "13333333333",
            "email": "abc@abc.com",
            "address": "长春",
            "jobFairName": "长春招聘会",
            "level": "50-100"
        },
        {
            "id": '11',
            "jobId": "aaaaaa",
            "jobFairId": "bbbbbb",
            "comId": "cccccc",
            "comName": "长春今非昔比",
            "posName": "java开发工程师",
            "posNature": "有限公司",
            "posArea": "长春",
            "salary": "3000-5000",
            "partment": "技术部",
            "education": "4",
            "experience": 1,
            "gender": "不限",
            "age": "18-28",
            "wantedNum": "5",
            "jobDescrib": "java开发",
            "linkman": "hr",
            "mobile": "13333333333",
            "email": "abc@abc.com",
            "address": "长春",
            "jobFairName": "长春招聘会",
            "level": "50-100"
        },
        {
            "id": '12',
            "jobId": "aaaaaa",
            "jobFairId": "bbbbbb",
            "comId": "cccccc",
            "comName": "长春今非昔比",
            "posName": "java开发工程师",
            "posNature": "有限公司",
            "posArea": "长春",
            "salary": "3000-5000",
            "partment": "技术部",
            "education": "4",
            "experience": 1,
            "gender": "不限",
            "age": "18-28",
            "wantedNum": "5",
            "jobDescrib": "java开发",
            "linkman": "hr",
            "mobile": "13333333333",
            "email": "abc@abc.com",
            "address": "长春",
            "jobFairName": "长春招聘会",
            "level": "50-100"
        },
    ]
}
Mock.mock(RegExp('/api/position/list' + ".*"), 'get', (request) => {
    const req = parseUrl(request.url);
    let _positionList = JSON.parse(JSON.stringify(positionList));

    return new Reponse().splitPage(_positionList.rows, req.pageSize, req.pageNumber).run()
});


Mock.mock('/api/resetpwd', 'post', (request) => {
    const req = JSON.parse(request.body);
    if(req['code'] !== getCode) return new Reponse({}, '验证码输入错误', '250').run();
    if(user_list[req.mobile] == undefined) return new Reponse({}, '该用户未注册', '251').run();
    user_list[req.mobile] = req.password;
    return new Reponse({},'修改成功', 0)
});

let jobfairList = {
      "pageSize": "10",
      "totalPages": "2",
      "pageNumber": "1",
      "total": "13",
      "rows": [
        {
          "id": 0,
          "jobFairId": "123",
          "jobFairName": "长春大学专场招聘会",
          "schoolName": "长春大学",
          "schoolLogo": "xxxxxxx.png",
          "schoolIntroduce": "长春大学。。。。。。。",
          "schoolAddr": "吉林省长春市",
          "startTime": "2019-03-01",
          "endTime": "2019-03-02",
          "education": "本科以上",
          "jobFairDescribe": "本次招聘会。。。。。。。。。",
          "applyStatus": "0",
          "create_time": "2019-02-03",
          "status": "0"
        },{
            "id": 1,
            "jobFairId": "123",
            "jobFairName": "长春大学专场招聘会",
            "schoolName": "长春大学",
            "schoolLogo": "xxxxxxx.png",
            "schoolIntroduce": "长春大学。。。。。。。",
            "schoolAddr": "吉林省长春市",
            "startTime": "2019-03-01",
            "endTime": "2019-03-02",
            "education": "本科以上",
            "jobFairDescribe": "本次招聘会。。。。。。。。。",
            "applyStatus": "0",
            "create_time": "2019-02-03",
            "status": "1"
          },{
            "id": 2,
            "jobFairId": "123",
            "jobFairName": "长春大学专场招聘会",
            "schoolName": "长春大学",
            "schoolLogo": "xxxxxxx.png",
            "schoolIntroduce": "长春大学。。。。。。。",
            "schoolAddr": "吉林省长春市",
            "startTime": "2019-03-01",
            "endTime": "2019-03-02",
            "education": "本科以上",
            "jobFairDescribe": "本次招聘会。。。。。。。。。",
            "applyStatus": "0",
            "create_time": "2019-02-03",
            "status": "1"
          },{
            "id": 3,
            "jobFairId": "123",
            "jobFairName": "长春大学专场招聘会",
            "schoolName": "长春大学",
            "schoolLogo": "xxxxxxx.png",
            "schoolIntroduce": "长春大学。。。。。。。",
            "schoolAddr": "吉林省长春市",
            "startTime": "2019-03-01",
            "endTime": "2019-03-02",
            "education": "本科以上",
            "jobFairDescribe": "本次招聘会。。。。。。。。。",
            "applyStatus": "0",
            "create_time": "2019-02-03",
            "status": "1"
          },{
            "id": 4,
            "jobFairId": "123",
            "jobFairName": "长春大学专场招聘会",
            "schoolName": "长春大学",
            "schoolLogo": "xxxxxxx.png",
            "schoolIntroduce": "长春大学。。。。。。。",
            "schoolAddr": "吉林省长春市",
            "startTime": "2019-03-01",
            "endTime": "2019-03-02",
            "education": "本科以上",
            "jobFairDescribe": "本次招聘会。。。。。。。。。",
            "applyStatus": "0",
            "create_time": "2019-02-03",
            "status": "2"
          },{
            "id": 5,
            "jobFairId": "123",
            "jobFairName": "长春大学专场招聘会",
            "schoolName": "长春大学",
            "schoolLogo": "xxxxxxx.png",
            "schoolIntroduce": "长春大学。。。。。。。",
            "schoolAddr": "吉林省长春市",
            "startTime": "2019-03-01",
            "endTime": "2019-03-02",
            "education": "本科以上",
            "jobFairDescribe": "本次招聘会。。。。。。。。。",
            "applyStatus": "0",
            "create_time": "2019-02-03",
            "status": "2"
          },{
            "id": 6,
            "jobFairId": "123",
            "jobFairName": "长春大学专场招聘会",
            "schoolName": "长春大学",
            "schoolLogo": "xxxxxxx.png",
            "schoolIntroduce": "长春大学。。。。。。。",
            "schoolAddr": "吉林省长春市",
            "startTime": "2019-03-01",
            "endTime": "2019-03-02",
            "education": "本科以上",
            "jobFairDescribe": "本次招聘会。。。。。。。。。",
            "applyStatus": "0",
            "create_time": "2019-02-03",
            "status": "1"
          },{
            "id": 7,
            "jobFairId": "123",
            "jobFairName": "长春大学专场招聘会",
            "schoolName": "长春大学",
            "schoolLogo": "xxxxxxx.png",
            "schoolIntroduce": "长春大学。。。。。。。",
            "schoolAddr": "吉林省长春市",
            "startTime": "2019-03-01",
            "endTime": "2019-03-02",
            "education": "本科以上",
            "jobFairDescribe": "本次招聘会。。。。。。。。。",
            "applyStatus": "0",
            "create_time": "2019-02-03",
            "status": "0"
          },{
            "id": 8,
            "jobFairId": "123",
            "jobFairName": "长春大学专场招聘会",
            "schoolName": "长春大学",
            "schoolLogo": "xxxxxxx.png",
            "schoolIntroduce": "长春大学。。。。。。。",
            "schoolAddr": "吉林省长春市",
            "startTime": "2019-03-01",
            "endTime": "2019-03-02",
            "education": "本科以上",
            "jobFairDescribe": "本次招聘会。。。。。。。。。",
            "applyStatus": "0",
            "create_time": "2019-02-03",
            "status": "1"
          },{
            "id": 9,
            "jobFairId": "123",
            "jobFairName": "长春大学专场招聘会",
            "schoolName": "长春大学",
            "schoolLogo": "xxxxxxx.png",
            "schoolIntroduce": "长春大学。。。。。。。",
            "schoolAddr": "吉林省长春市",
            "startTime": "2019-03-01",
            "endTime": "2019-03-02",
            "education": "本科以上",
            "jobFairDescribe": "本次招聘会。。。。。。。。。",
            "applyStatus": "0",
            "create_time": "2019-02-03",
            "status": "1"
          },
          {
            "id": 10,
            "jobFairId": "123",
            "jobFairName": "长春大学专场招聘会",
            "schoolName": "长春大学",
            "schoolLogo": "xxxxxxx.png",
            "schoolIntroduce": "长春大学。。。。。。。",
            "schoolAddr": "吉林省长春市",
            "startTime": "2019-03-01",
            "endTime": "2019-03-02",
            "education": "本科以上",
            "jobFairDescribe": "本次招聘会。。。。。。。。。",
            "applyStatus": "0",
            "create_time": "2019-02-03",
            "status": "1"
          },{
            "id": 11,
            "jobFairId": "123",
            "jobFairName": "长春大学专场招聘会",
            "schoolName": "长春大学",
            "schoolLogo": "xxxxxxx.png",
            "schoolIntroduce": "长春大学。。。。。。。",
            "schoolAddr": "吉林省长春市",
            "startTime": "2019-03-01",
            "endTime": "2019-03-02",
            "education": "本科以上",
            "jobFairDescribe": "本次招聘会。。。。。。。。。",
            "applyStatus": "0",
            "create_time": "2019-02-03",
            "status": "1"
          },{
            "id": 12,
            "jobFairId": "123",
            "jobFairName": "长春大学专场招聘会",
            "schoolName": "长春大学",
            "schoolLogo": "xxxxxxx.png",
            "schoolIntroduce": "长春大学。。。。。。。",
            "schoolAddr": "吉林省长春市",
            "startTime": "2019-03-01",
            "endTime": "2019-03-02",
            "education": "本科以上",
            "jobFairDescribe": "本次招聘会。。。。。。。。。",
            "applyStatus": "0",
            "create_time": "2019-02-03",
            "status": "1"
          },
      ]
  }

Mock.mock('/api/jobfair/list', 'post', (request) => {
    const req = JSON.parse(request.body);
    console.log(req)
    let _jobfairList = JSON.parse(JSON.stringify(jobfairList));
    if(req.status) _jobfairList.rows = new Reponse().filterPage(_jobfairList.rows,'status', req.status);
    if(req.keyword) return;
    _jobfairList = new Reponse().splitPage(_jobfairList.rows, req.pageSize, req.pageNumber).run();
    return _jobfairList;
});